// 是否为群消息
function isGroupMsg(content) {
    return /^@[^<]+<br\/>.+/.test(content);
}

/**
 * 匹配是否为群里面有人@我的信息
 * @param message
 * @returns {boolean}
 */
function isGroupMsgToMe(myUserName, content) {
    // /^@[^<]+<br\/>@.+\s(.+)/
    var reg = new RegExp('^@[^<]+<br/>@' + myUserName + '\\s.+');
    return reg.test(content);
}

/**
 * 获取对话信息
 * @param content
 */
function matchGroupContent(content) {
    //let [all, message] = /^@[^<]+<br\/>@.+\s(.+)/.exec(content)
    var regExp = /^([^<]+):<br\/>(.*)@.+\s(.*)/;
    var fromMemberId, messageField;
    if (regExp.test(content)) {
        let [all, fromUserName, messageRrev, messageNext] = regExp.exec(content);
        fromMemberId = fromUserName;
        messageField = messageRrev + messageNext;
    } else if (/^([^<]+):<br\/>(.*)/) {
        let [all, fromUserName, message] = regExp.exec(content);
        fromMemberId = fromUserName;
        messageField = message;
    }
    return {
        fromMemberId: fromMemberId,
        message: messageField
    };
}

module.exports = {
    isGroupMsg: isGroupMsg,
    isGroupMsgToMe: isGroupMsgToMe,
    matchGroupContent: matchGroupContent
}